In [15]:
import bokeh
from bokeh.plotting import figure
import bokeh.plotting as plotting
from bokeh.io import output_file, show, save
from bokeh.tile_providers import CARTODBPOSITRON
from bokeh.util.browser import view
from bokeh.models.glyphs import Circle
from bokeh.models import (
    GMapPlot, Range1d, ColumnDataSource,
    PanTool, WheelZoomTool, BoxZoomTool, ResetTool, GMapOptions)
import yaml
import pandas as pd
from IPython.core.display import display, HTML
from IPython.display import Image
from utils import toWebMercator
import numexpr as ne
import numpy as np

In [2]:
plotting.output_notebook()


Loading BokehJS ...

In [3]:
with open('../utils/credentials.yaml') as f:
    credentials = yaml.load(f)
API_KEY = credentials['api_key']

In [4]:
file = r'D:\ADSB\working\h5\2017-01-16.h5'

In [5]:
store = pd.HDFStore(file)

In [6]:
points = store.select('data',columns=['Lat','Long']).dropna()
points = points.query('Lat>=-90').query('Lat<=90').query('Long>=-180').query('Long<=180')
points.head()


Out[6]:
Lat Long
6 23.450592 113.342050
10 0.000001 0.000000
13 -45.629898 0.000000
18 29.147690 106.679146
24 32.542408 -116.973580

In [7]:
points_reduced = points.drop_duplicates()

In [23]:
plotting.output_notebook()


Loading BokehJS ...

In [24]:
x_range = Range1d(-160, 160)
y_range = Range1d(-80, 80)

map_options = GMapOptions(lat=33.75,
                          lng=-80.39, 
                          map_type="roadmap",
                          zoom=2)

plot = GMapPlot(
    x_range=x_range,
    y_range=y_range,
    map_options=map_options,
    api_key=API_KEY,
)
plot.title.text = "Aircraft Received Positions for Single Day"
circle = Circle(x="Long", y="Lat", size=5, line_color=None, fill_color='firebrick', fill_alpha=0.9)
plot.add_glyph(ColumnDataSource(points_reduced), circle)
plot.add_tools(PanTool(), WheelZoomTool(), BoxZoomTool(),ResetTool())
show(plot)


Note: the above does not consistnly render in the notebook. Below is a picture of the plot. This can be achieved by changing the show command to save and providing a filename.


In [26]:
Image('gmap.png')


Out[26]:

In [28]:
x_we, y_we = toWebMercator(points['Long'],points['Lat'])

In [29]:
fig = figure(tools='pan, wheel_zoom, box_zoom, reset')
fig.circle(x=x_we,y=y_we,color='blue', size=2, alpha=0.4)
fig.axis.visible = False
fig.add_tile(CARTODBPOSITRON)

show(fig)



In [ ]: